package com.taobao.dao.impl;

import java.util.List;

import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.eclipse.swt.graphics.Image;

import com.taobao.dao.CommonDao;
import com.taobao.dao.ValidateCodeDao;
import com.taobao.pojo.Config;
import com.taobao.pojo.HttpContext;

public class ValidateCodeDaoImpl extends CommonDao implements ValidateCodeDao {

	public Image getValidateImage() throws Exception {
		Image image = (Image) this.getRequestForStream(Config.url + "code.aspx");
		return image;
	}

	@Override
	public Object process(HttpContext context) throws Exception {
		Image image = new Image(null, context.getEntity().getContent());
		Config.cookieStore = context.getCookieStore();
		CookieStore cookieStore = Config.cookieStore;
		List<Cookie> cs = cookieStore.getCookies();
		for (int i = 0; i < cs.size(); i++) {
            System.out.println(cs.get(i).getName()+", "+cs.get(i).getValue());
        }
		return image;
	}
}
